<template>
    <div class="layout-route">
        <div class="card card-search">
            <el-form :model="queryParams" ref="queryForm" v-show="showSearch" inline label-width="100px">
                <el-form-item label="广告账户" prop="advertiser_id">
                    <el-input v-model.trim="queryParams.advertiser_id" placeholder="请输入广告账户" clearable size="small" style="width: 240px" @keyup.enter.native="handleQuery" />
                </el-form-item>
                <el-form-item label=" ">
                    <el-button type="primary" icon="el-icon-search" @click="handleQuery">搜索</el-button>
                    <el-button icon="el-icon-refresh" @click="resetQuery">重置</el-button>
                </el-form-item>
            </el-form>
        </div>

        <div class="card">
            <el-row :gutter="10" class="mb8">
                <el-col :span="1.5">
                    <!-- <el-button type="primary" plain icon="el-icon-plus" @click="showDetailDialog({}, 'add')">添加</el-button> -->
                </el-col>
                <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
            </el-row>
            <el-tabs v-model="queryParams.platform_id" type="border-card" @tab-click="handleQuery">
                <el-tab-pane label="全部" :name="undefined"></el-tab-pane>
                <el-tab-pane v-for="item in platformList" :key="item.id" :label="item.title" :name="item.id.toString()"></el-tab-pane>
            </el-tabs>
            <div class="table-wrap">
                <el-table v-loading="loading" :data="tableData" border script>
                    <!-- <el-table-column label="开户主体" prop="advertiser_name" min-width="200" show-overflow-tooltip></el-table-column> -->
                    <el-table-column label="平台" prop="platform_title" min-width="120" show-overflow-tooltip></el-table-column>
                    <el-table-column label="广告账户" prop="advertiser_id" min-width="180" show-overflow-tooltip></el-table-column>
                    <el-table-column label="错误" prop="error" min-width="320" show-overflow-tooltip></el-table-column>
                    <el-table-column label="错误时间" prop="stat_time" min-width="120"></el-table-column>

                    <el-table-column label="操作" min-width="160" fixed="right">
                        <template slot-scope="scope">
                            <!-- <el-button type="text" icon="el-icon-edit" @click="showDetailDialog(scope.row, 'edit')">编辑</el-button>
                            <el-button type="text" icon="el-icon-search" @click="toAscription(scope.row)">账户归属</el-button> -->
                            <el-button type="text" icon="el-icon-edit" @click="advaccountAbnormalConfirm(scope.row)">确认处理</el-button>
                        </template>
                    </el-table-column>
                </el-table>
            </div>
            <pagination v-show="total > 0" :total="total" :page.sync="pageInfo.page" :limit.sync="pageInfo.limit" @pagination="getList"></pagination>
        </div>

        <detail-dialog v-model="detailDialog.visible" v-if="detailDialog.visible" :params="detailDialog.data" :type="detailDialog.type" @success="handleQuery"></detail-dialog>
    </div>
</template>

<script>
import { queryAdvaccountAbnormalList, queryAdvplatformList, advaccountAbnormalConfirm } from '@/api/advertisement'
import DetailDialog from './components/DetailDialog.vue'
export default {
    name: 'AdvaccountList',
    components: { DetailDialog },
    data() {
        return {
            // 遮罩层
            loading: true,
            // 显示搜索条件
            showSearch: true,
            // 总条数
            total: 0,
            // 表格数据
            tableData: [],
            platformList: [],
            pageInfo: {
                page: 1,
                limit: 10,
            },
            // 查询参数
            queryParams: {
                shop_id: undefined,
                admin_id: undefined,
                advertiser_id: undefined,
                platform_id: undefined,
            },
            detailDialog: {
                visible: false,
                data: {},
            },
        }
    },
    async created() {
        this.loading = true
        try {
            const platformData = await queryAdvplatformList()
            this.platformList = platformData?.data?.list ?? []
        } catch (error) {
            this.loading = false
            console.log(error)
        }
        this.getList()
    },
    methods: {
        showDetailDialog(row, type) {
            this.detailDialog.visible = true
            this.detailDialog.data = row
            this.detailDialog.type = type
        },
        toAscription(row) {
            this.$router.push({
                path: '/advertisement/ascription',
                query: {
                    advertiser_id: row.advertiser_id,
                },
            })
        },
        //列表
        getList() {
            this.loading = true
            const qyparams = {
                ...this.pageInfo,
                ...this.queryParams,
            }
            queryAdvaccountAbnormalList(qyparams)
                .then(response => {
                    this.tableData = response.data.list
                    this.total = response.data.total
                })
                .finally(() => {
                    this.loading = false
                })
        },
        advaccountAbnormalConfirm(row) {
            this.$confirm('是否确认处理', '提示', {
                confirmButtonText: '确定',
                cancelButtonText: '取消',
                type: 'warning',
            }).then(()=>{
                advaccountAbnormalConfirm({id: row.id}).then(()=>{
                    this.$message.success('操作成功')
                    this.handleQuery()
                })
            })
        },

        // 搜索按钮操作
        handleQuery() {
            this.pageInfo.page = 1
            this.getList()
        },

        // 重置按钮操作
        resetQuery() {
            this.resetForm('queryForm')

            this.handleQuery()
        },
    },
}
</script>
<style scoped>
::v-deep .el-tabs .el-tabs__content {
    padding: 0;
    border-bottom: 0;
}
.el-tabs--border-card {
    box-shadow: none;
    border-bottom: 0;
}

::v-deep .el-tabs .el-tabs__content {
    padding: 0;
    border-bottom: 0;
}
.table-wrap {
    padding: 15px;
    border-bottom: 1px solid #dfe4ed;
    border-left: 1px solid #dfe4ed;
    border-right: 1px solid #dfe4ed;
    box-shadow: 0 2px 4px 0 rgba(0, 0, 0, 0.12), 0 0 6px 0 rgba(0, 0, 0, 0.04);
}
</style>
